<template>
    <el-container>
        <el-container class="is-vertical">
            <div class="panel-search-box">
                <div class="panel-search">
                    <el-input v-model="search.versionNumber" placeholder="版本号" clearable></el-input>
                    <el-select v-model="search.type" placeholder="应用端" clearable>
                        <el-option label="Android" :value="1"></el-option>
                        <el-option label="IOS" :value="2"></el-option>
                    </el-select>
                    <el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
                </div>
            </div>
            <el-main class="nopadding">
                <scTable ref="table" :apiObj="$API.applyVersion.list" remoteSort :params="search" @selection-change="selectionChange">
                    <el-table-column label="应用端" prop="type.name" width="150" align="left"></el-table-column>
                    <el-table-column label="版本号" prop="versionNumber" width="150" align="center"></el-table-column>
                    <el-table-column label="下载地址" prop="download.show" align="center"></el-table-column>
                    <el-table-column label="强制更新" prop="forcedUpdating" width="150" align="center">
                        <template #default="scope">
                            <el-tag size="mini" v-if="scope.row.forcedUpdating.value == 1" :type="scope.row.forcedUpdating.value == 1 && 'success'">{{scope.row.forcedUpdating.name}}</el-tag>
                            <el-tag size="mini" v-else :type="scope.row.forcedUpdating.value == 0 && 'danger'">{{scope.row.forcedUpdating.name}}</el-tag>
                        </template>
                    </el-table-column>
                    <el-table-column label="更新时间" prop="updatedAt" width="150" align="center"></el-table-column>
                    <el-table-column label="操作" fixed="right" align="center" width="150">
                        <template #default="scope">
                            <el-button type="text" size="small" @click="table_edit(scope.row)" v-auth="'system-applyVersion-edit'">编辑</el-button>
                        </template>
                    </el-table-column>
                </scTable>
            </el-main>
        </el-container>
    </el-container>
    <save-dialog v-if="dialog.save" ref="saveDialog"  @success="handleSuccess" @closed="dialog.save=false"></save-dialog>
</template>

<script>
import saveDialog from './save'

export default {
    name: 'user',
    components: {
        saveDialog
    },
    data() {
        return {
            dialog: {
                save: false,
                detail: false
            },
            groupFilterText: '',
            group: [],
            selection: [],
            search: {
                name: null,
                status: null,
            },
            //角色列表
            rolelist: []
        }
    },
    watch: {
        groupFilterText(val) {
            this.$refs.group.filter(val);
        }
    },
    mounted() {
    },
    methods: {
        // 搜索
        upsearch() {
            this.$refs.table.upData(this.search)
        },
        // 增加
        table_add() {
            this.dialog.save = true
            this.$nextTick(() => {
                this.$refs.saveDialog.open()
            })
        },
        // 编辑
        table_edit(row) {
            this.dialog.save = true
            this.$nextTick(() => {
                this.$refs.saveDialog.open('edit').setData(row)
            })
        },
        //表格选择后回调事件
        selectionChange(selection) {
            this.selection = selection;
        },
        //本地更新数据
        handleSuccess() {
            this.$refs.table.refresh()
        }
    }
}
</script>

<style>
</style>
